package com.tanhua.dubbo.api;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.tanhua.dubbo.mappers.UserMapper;
import com.tanhua.model.domain.User;
import org.apache.commons.lang.StringUtils;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

@DubboService
public class UserApiImpl implements UserApi{
    @Autowired
    private UserMapper userMapper;
    //根据手机号查询用户
    public User findByMobile(String mobile) {
        LambdaQueryWrapper<User> queryWrapper=new LambdaQueryWrapper<>();
        queryWrapper.eq(StringUtils.isNotEmpty(mobile),User::getMobile,mobile);
        return userMapper.selectOne(queryWrapper);
    }

    //保存用户，返回用户id
    public Long save(User user) {
        userMapper.insert(user);
        return user.getId() ;
    }
}
